﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace TestEval
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            Double val = RoslynEval.Eval.Evaluate(this.textBox1.Text);
            this.textBox2.Text = Convert.ToString(val);
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            this.textBox2.Text = RoslynEval.Eval.StringToDouble(this.textBox1.Text).ToString();
        }

        private void button3_Click(object sender, RoutedEventArgs e)
        {
            String equation = this.textBox3.Text;
            String[] variableNames = Split(this.textBox4.Text,",").ToArray();
            String[] variableValueStrings = Split(this.textBox5.Text, ",").ToArray();
            Double[] variableValues = Functional.Maps.Map(variableValueStrings, Convert.ToDouble);
            

            RoslynEval.Eval eval = new RoslynEval.Eval();
            eval.SetAssembly(equation, variableNames);
            this.textBox6.Text = eval.CallAssembly(variableValues).ToString();
        }

        public static List<String> Split(String inString, String inOperator, Boolean removeEmptyEntries = false)
        {
            String[] seperators = new String[1];
            seperators[0] = inOperator;
            String[] strs;
            if (removeEmptyEntries == true)
            {
                strs = inString.Split(seperators, StringSplitOptions.RemoveEmptyEntries);
            }
            else
            {
                strs = inString.Split(seperators, StringSplitOptions.None);
            }
            List<String> lOut = strs.ToList<String>();
            return lOut;
        }
    }
}
